import java.util.concurrent.locks.ReentrantLock;

/**
 * <p>
 * </p>
 *
 * @author zhuolin
 * @since 2020/5/29
 */
public class ReenterLock implements Runnable {

    public static ReentrantLock lock = new ReentrantLock();
    static int i = 0;

    @Override
    public void run() {
        for (int j = 0; j < 10000; j++) {
            lock.lock();
            try {
                i++;
            } finally {
                lock.unlock();
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        ReenterLock reenterLock = new ReenterLock();
        Thread t = new Thread(reenterLock);
        Thread t1 = new Thread(reenterLock);
        t.start();t1.start();
        t.join();t1.join();
        System.out.println(i);
    }
}
